#!/bin/bash

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "${SCRIPT_DIR}"

REPO_ROOT="$(git rev-parse --show-toplevel)"
cd "${REPO_ROOT}"

echo "$@"

# venv activate
source "${REPO_ROOT}/venv/bin/activate"
cd python

DB_CONFIG="${REPO_ROOT}/../coin_deploy/support_instrument_feed/db_config/db_config_prod.json"
if [ -n "${1}" ]; then
  DB_CONFIG="${1}"
fi

LOG_DIR="${REPO_ROOT}/log"
mkdir -p "${LOG_DIR}"
DATE="$(date +%Y%m%d)"
LOG_PATH="${LOG_DIR}/${DATE}"

./pyrunner \
  coin/support/feed_archive/app/okex_futures_instrument_feed_collector.py \
  --db_config="${DB_CONFIG}" "$@" > ${LOG_PATH} 2>&1

deactivate
